package cn.zy.gvs.v1.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.zy.gvs.v1.mapper.GoViewProjectDataMapper;
import cn.zy.gvs.v1.model.GoViewProjectData;
import cn.zy.gvs.v1.service.IGoViewProjectDataService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author yann
 */
@Service
public class GoViewProjectDataServiceImpl extends ServiceImpl<GoViewProjectDataMapper, GoViewProjectData>
        implements IGoViewProjectDataService {

    @Override
    public boolean insertOrUpdate(GoViewProjectData goViewProjectData) {

        GoViewProjectData data = baseMapper.selectOne(Wrappers.<GoViewProjectData>lambdaQuery()
                .eq(GoViewProjectData::getProjectId, goViewProjectData.getProjectId()));
        if (ObjectUtil.isNull(data)) {
            return baseMapper.insert(goViewProjectData) > 0;
        } else {
            goViewProjectData.setId(data.getId());
            return baseMapper.updateById(goViewProjectData) > 0;
        }
    }
}
